import os
import json
trajectories_save_path='hotpot/trajectories_bad-thought/trajectories_train_gpt-4o-mini_lats_30iterations_1000samples'
length_list = []

for file in os.listdir(trajectories_save_path):
    if not file.endswith('json'):
        continue
    with open(os.path.join(trajectories_save_path, file)) as f:
        result=json.load(f)
    if result['best child em'] == 1:
        length_list.append(len(result['best_trajectory_index_list']))
print("Average succeed length: ", sum(length_list)/len(length_list))
